package com.frank.oj.controller.oj;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.frank.oj.annotation.AnonApi;
import com.frank.oj.common.exception.StatusFailException;
import com.frank.oj.common.result.CommonResult;
import com.frank.oj.service.oj.RankService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 排名
 *
 * @author frank
 * @Date 2024/4/17
 */
@RestController
@RequestMapping("/api")
@AnonApi
public class RankController {
    @Resource
    private RankService rankService;

    @GetMapping("/get-rank-list")
    public CommonResult<IPage> getRankList(@RequestParam(value = "limit", required = false) Integer limit,
                                           @RequestParam(value = "currentPage", required = false) Integer currentPage,
                                           @RequestParam(value = "searchUser", required = false) String searchUser,
                                           @RequestParam(value = "type", required = true) Integer type) {

        try {
            return CommonResult.successResponse(rankService.getRankList(limit,currentPage,searchUser,type));
        } catch (StatusFailException e) {
            return CommonResult.errorResponse(e.getMessage());
        }
    }
}
